package com.emperor.controller.vmservice;

import com.emperor.dto.SkuSaveDto;
import com.emperor.result.Result;
import com.emperor.service.SkuService;
import com.emperor.vo.SkuClassPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/vm-service/sku")
@Api(tags = "商品管理")
public class SkuController {

    @Autowired
    private SkuService skuService;

    /**
     * 新增商品
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增商品")
    @PostMapping
    public Result save(@RequestBody SkuSaveDto dto) {
        skuService.save(dto);
        return Result.success();
    }

    /**
     * 商品搜索
     *
     * @return
     */
    @ApiOperation("商品搜索")
    @GetMapping("/search")
    public Result<SkuClassPageVo> findAll(Integer pageIndex, Integer pageSize, String className) {
        SkuClassPageVo vo = skuService.findAll(pageIndex, pageSize, className);

        return Result.success(vo);
    }

    /**
     * 修改商品
     * @param skuId
     * @return
     */
    @ApiOperation("修改商品")
    @GetMapping("/sku/{skuId}")
    public Result updateById(@PathVariable String skuId, @RequestBody SkuSaveDto dto) {
        skuService.updateById(skuId, dto);
        return Result.success();
    }
}
